package com.qf.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;

/**
 *
 * @Configuration:此类相当于是一个配置文件（可以完全取代xml配置文件）
 * @author YDW
 * projectName:project2202_3
 * time:2022/5/6 21:28
 * description:
 */
//@Configuration
//@ComponentScan(basePackages = "com.qf.service")
//@PropertySource("classpath:jdbc.properties")
public class SpringConfig {

    @Value("jdbc.driverClass")
    private String diverClass;
    @Value("jdbc.url")
    private String url;
    @Value("jdbc.username")
    private String username;
    @Value("jdbc.password")
    private String password;

    @Bean("dataSource")
    public DataSource createDataSource(){
        DruidDataSource dataSource=new DruidDataSource();
        dataSource.setDriverClassName(diverClass);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;

    }
}
